          SUBROUTINE (ROOT)
** Version# 44.0005[14] - 08/08/2017 - 12:00pm - TSMITH - eclipse
*** V44.0005 Change - Custom Coding . - 08/08/2017 - TSMITH - eclipse
** Copied from CBP UD.DVR.DOC.PRINT Version# 44.0004[11] - 08/08/2017 - 09:09am - TSMITH - eclipse
*** V44.0004 Change - Custom Coding . - 08/08/2017 - TSMITH - eclipse
*** V44.0003 Change - Custom Coding . - 07/13/2017 - TSMITH - eclipse
*** V44.0002 Change - Custom Coding . - 12/23/2014 - TSMITH - eclipse
*** V44.0001 Change - Custom Coding CUSTOM - 10/29/2013 - TSMITH - eclipse
*** Subroutine - UD.DVR.DOC.PRINT
*-------------------------------------------------------------------------*
*** Driver program that displays one of two screens based on the TYPE
*** passed in:
***
*** Option #1 - User Defined Document/Label Printing (has 4 prompts)
*** Use this screen to to print labels for shipping or for printing other
*** custom documents.  From SOE, use the "Ship Qty / Label Qty" to
*** specify the # of labels to print for each product on the order
*** Note! You can edit the quantity of labels to print even if the order
*** is in view-only mode.
***
***                      -- OR --
***
*** Option #2 - User Defined Upload Processing (has 1 prompt)
*** Use this screen to upload data from text files and process using
*** a specific processing routine - accessed from the alt-f2 Spooler
*** Control Hold file screen.
*-------------------------------------------------------------------------*
*** TYPE        - UD document type - see UD.DOC.PRINT.INIT          (IN)
***               'T' - Transfers - CONTROL~UD.XFER.FORMATS
***               'S' - Sales     - CONTROL~UD.SHIP.FORMATS
***               'R' - RF        - CONTROL~UD.RECV.FORMATS
***               'C' - Customer  - CONTROL~UD.CUST.FORMATS
***               'P' - Print     - CONTROL~UD.PROD.FORMATS
***               'U' - Hold File - CONTROL~UD.UPLOAD.FORMATS
***               'N' - Shipments - CONTROL~UD.RECV.FORMATS
*** UID         - user defined ID                                   (IN)
*** OID         - Order ID                                          (IN)
*** GEN         - Generation                                        (IN)
*** ORIG.LDID   - Typically the LDID selected when this routine     (IN)
***               was called.  Use for printing the Current Item
***               Only.  However, if call originated at
***               Warehouse Picking Confirmation screen then
***               the following information is encoded:
***               <7,1> = 'PICK.CONF'   - String to identify
***                                       source of call
***               <7,2> = TOTAL.PKG.CNT - Total package count
***                                       defined on that screen
*** UFORMAT     - user defined format                               (IN)
*** UQTY        - user defined qty                                  (IN)
*** CALLED.FROM - Origin of this routine (1=OE,2=RF,blank=unknown)  (IN)
*** CTN.DATA    - Carton detailed data to allow printing of all
***               products in a given carton                        (IN)
*-------------------------------------------------------------------------*
*** Common: None
*-------------------------------------------------------------------------*
          TYPE = 'N'
          CALLED.FROM=''
          OID = ''
          CTN.DATA = ''
          UQTY = ''
          UFORMAT=''
          UID = ''
          GEN = ''
          ORIG.LDID = ''
          MSG=''
                    READ FORMATS FROM CTRLFILE,'UD.SHIP.FORMATS' ELSE
             FORMATS =''
          END

          SUBR.NAME   = FORMATS<2,1>


             SCRN    = 'UD.DVR.DOC.DOWNLOAD'
          WINDOW SCRN=SCRN


             MENU.LOAD  2,6,8,1,'D'

          IF UNASSIGNED(UQTY) OR UQTY = '' THEN QTY = 1 ELSE QTY = UQTY
          AUTORTN = NO

          GOSUB INIT

*          FORMATS = 'Delivery Schedule'
          IF FORMATS = '' THEN
             MESS 15,2,BELL:'No Formats Defined'
IN$$1:       INPNO A
             GOTO FINISH
          END
          IF UFORMAT AND UFORMAT = FORMAT THEN
             AUTORTN = YES
             GOSUB PRT.LBLS
          END
*-------------------------------------------------------------------------*
INFMT:    INP FORMAT,20,1,30,V_'D:':FORMATS<1>,HELPSCR=HELP.ID
          IF F12 THEN GOTO FINISH
          IF CHANGED THEN GOSUB UPD.FRMT; GOSUB DISPLAY
          IF QUIT THEN GOTO FINISH
          IF TYPE='U' THEN GOTO INFMT
          ON MOVE+1 GOTO INFMT, INFMT, INFMT, INFMT
*-------------------------------------------------------------------------*
INSEL:    INP SELCT,20,2,30,V_'D:':PRT.SELCTS
          IF F12 THEN GOTO FINISH
          IF CHANGED THEN GOSUB DISPLAY
          IF QUIT THEN GOTO FINISH
          ON MOVE+1 GOTO INSEL, INSEL, INFMT, INSEL
*-------------------------------------------------------------------------*
          *** Get the number of labels to print.  The initial number
          *** displayed is a best guess depending upon previously supplied
          *** information.  However, the user can override this guess.
          *** TOL.CNT<1> contains the number of labels to print.
          ***            Initially this contains the BEST GUESS at the
          ***            number of number of labels needed.
          *** TOL.CNT<2> MAY contain a 'Y' if the user changes
          ***            the number of labels to print.
INCNT:    INP TOL.CNT<1>,20,3,5,'R'

          * QTYP indicates the type of Label Printing that will be
          * done.  The set of integer Constants to be used for this
          * variable are defined in UD.DOC.PRINT.GET.SELCTS.
          IF CHANGED AND QTYP = SELCT.VALUE.ALL.ITEMS THEN TOL.CNT<2> = 'Y'
          IF QUIT THEN GOTO FINISH

          * When we are printing the Current Item, it makes sense to
          * ask how many items are in a box.  Otherwise, specifying the
          * box quantity does not make much sense; so don't allow the
          * user to get to that field.
          IF QTYP=SELCT.VALUE.CURRENT.ITEM THEN
             ON MOVE+1 GOTO INCNT, INCNT, INSEL, INCNT, INBXQY,INBXQY
          END ELSE
             ON MOVE+1 GOTO INCNT, INCNT, INSEL, INCNT, INCNT,INCNT
          END
*-------------------------------------------------------------------------*
INBXQY:   INP BOX.QTY,20,4,5,'R'
          IF QUIT THEN GOTO FINISH
          ON MOVE+1 GOTO INBXQY,INBXQY,INCNT,INBXQY,INBXQY,INBXQY,INBXQY
*-------------------------------------------------------------------------*
INIT:     *** init variables

          BOX.QTY = ''

          PASSER      = ''
          PASSER<1>   = OID
          PASSER<2>   = GEN
          PASSER<7>   = ORIG.LDID
          PASSER<12>  = UFORMAT
          PASSER<11>  = UQTY
          PASSER<8>   = UID
          PASSER<20>  = QTY
          PASSER<16>  = TYPE
          PASSER<33>  = LOWER(CTN.DATA)
          PASSER<21>  = CALLED.FROM




          * Preserve the original type to force part number perinting for
          * kit components
          PASSER<37>  = TYPE

          * Get the Print Selection TEXT STRING Constants that are
          * displayed to the user, and the INTEGER VALUES Constants that
          * represent these strings.
          UD.DOC.PRINT.GET.SELCTS SELCT.CURRENT.ITEM,SELCT.ALL.ITEMS,SELCT.ORDER.ONLY,SELCT.VALUE.CURRENT.ITEM,SELCT.VALUE.ALL.ITEMS,SELCT.VALUE.ORDER.ONLY

          UD.DOC.PRINT.INIT PASSER,,ERR.MSG
          IF ERR.MSG THEN
             ERR.MESS 1,1,ERR.MSG,YES
             RETURN TO FINISH
          END

          GOSUB SET.VARS
          GOSUB UPD.FRMT
          GOSUB DISPLAY

          RETURN
*-------------------------------------------------------------------------*
UPD.FRMT: *** The value of the "Doc/Lbl Format" field has changed.  (This
          *** routine is also called when this screen is initialized.)

          LOCATE FORMAT IN FORMATS<1> SETTING POS ELSE POS = 1
          ISPEC      = FORMATS<3,POS>
          PASSER<35> = ISPEC

          * Determine what text to display in "Print Selection".
          * The list of possible strings in in PRT.SELCTS which came
          * from PASSER<22> and were defined in UD.DOC.PRINT.INIT
          SELCT = ''
          IF ISPEC[1,1] # 'O' THEN
             GOSUB GET.SELCT.DFLT
          END ELSE
             IF MODE = 'O' OR UID<1,2> = 'SRE.INT' THEN
                * In these cases, there is only 1 possible value
                * in PRT.SELCTS returned from UD.DOC.PRINT.INIT
                * which is Order Only
                SELCT = PRT.SELCTS<1,1>
             END ELSE
                * We can have a different number of possible selections
                * so use the LAST one.  If there are 3, this will be
                * Order Only
                PRT.SELCT.CT = DCOUNT(PRT.SELCTS,VM)
                SELCT = PRT.SELCTS<1,PRT.SELCT.CT>
             END
          END


          SUBR.NAME  = FORMATS<2,POS>
          FORM       = FORMATS<4,POS>
          DDE.SUBR   = FORMATS<5,POS>
          AUTH.KEY   = FORMATS<6,POS>

          PASSER<29> = SUBR.NAME
          PASSER<30> = FORM
          PASSER<31> = DDE.SUBR
          PASSER<32> = AUTH.KEY
          PASSER<33> = LOWER(CTN.DATA)

          RETURN
*-------------------------------------------------------------------------*
GET.SELCT.DFLT: *** Determine the default value for the Print Selection
          *** input field.

          * Use the first item in the list of possible print selections
          * as the default.
          SELCT = PRT.SELCTS<1,1>

          * figure out if called from RF vs. SOE/POE/TOE
          IF CALLED.FROM = 2 THEN
             READV SELCT FROM CTRLFILE,'LABEL.DFLT.PRT.SEL.RF',1 ELSE NULL
          END ELSE
             CTRL.ID = 'LABEL.DFLT.PRT.SEL.':MODE:'OE'
             READV SELCT FROM CTRLFILE,CTRL.ID,1 ELSE NULL
          END

          RETURN
*-------------------------------------------------------------------------*
DISPLAY:  *** display info to the screen

          TOL.CNT = ''
          UD.DOC.PRINT.GET.DISP PASSER,SELCT,TOL.CNT,ERR.MSG
          QTYP = PASSER<36>
          IF ERR.MSG THEN
             ERR.MESS 1,1,ERR.MSG,YES
             RETURN
          END



          IF FORMAT[1,1]='B' OR FORMAT[1,1]='D' AND TYPE#'N' THEN
          SELCT = ''
          TOL.CNT = ''
          BOX.QTY = ''
          END


          IF TYPE = 'T' THEN
             IF RCV.MODE THEN
                PRINT @(7,4):'Recv':@(36,4):'Recv':@(50,3):'Recv'
             END
          END
          PRINT @(20,1):FORMAT                 "L#30"

          IF TYPE # 'U' THEN
             PRINT @(20,2):SELCT               "L#30"
             PRINT @(20,3):TOL.CNT<1>          "R#5"

             * When we are printing the Current Item, it makes sense to
             * ask how many items are in a box.  Otherwise, specifying the
             * box qty does not make much sense, so indicate to the user
             * that they are not allowed to enter anything in this field..
             IF QTYP=SELCT.VALUE.CURRENT.ITEM THEN
                * Display the current box quantity
                PRINT @(20,4):BOX.QTY   "R#5"
             END ELSE
                * Indicate to the user that the Box Qty is NOT allowed.
                BOX.QTY = ''
                PRINT @(20,4):"*****"
             END
          END

          RETURN
*-------------------------------------------------------------------------*
SUBS:     ON OPTION GOTO PRT.LBLS
*-------------------------------------------------------------------------*
PRT.LBLS: *** print lables

          IF AUTH.KEY THEN
             CHECK.KEY AUTH.KEY,ENTRY.OK
             IF NOT(ENTRY.OK) THEN
                MSG = 'Not Authorized For This Process!!'
                MESS 3,2,MSG
                RETURN TO INFMT
             END
          END

          * Unless we are printing the Current Item, we ignore
          * the box quantity because it doesn't make any sense in this
          * context.
          IF QTYP=SELCT.VALUE.CURRENT.ITEM THEN
             * This is the new boxed quantity section that will display the
             * correct warning message to the user.
             IF BOX.QTY AND BOX.QTY # 0  THEN
                * Change the number of labels needed for this item to the
                * number of labels needed for BOXES OF THESE ITEMS.
                ROUNDUP NEW.CNT,TOL.CNT<1>,BOX.QTY
                TOL.CNT<1> = NEW.CNT
             END
          END

          READ LBL.CTRL FROM CTRLFILE,'LABEL.QTY.CONTROL' ELSE LBL.CTRL=''
          BEGIN CASE
          CASE TOL.CNT<1> > LBL.CTRL<1,1,2> AND LBL.CTRL<1,1,2>#''
             ANS = ''
             PRINT BELL:
             MSG = "You are about to Print ":TOL.CNT<1>:" Labels/Docs!! Type 'CONTINUE' : "
IN$$2:       INP.PROMPT ANS,MSG,'MCU',8
             IF ANS#'CONTINUE' THEN RETURN
          CASE TOL.CNT<1> > LBL.CTRL<1,1,1> AND LBL.CTRL<1,1,1>#''
             ANS = ''
             PRINT BELL:
IN$$3:       INP.PROMPT ANS,"Do you Really want to Print ":TOL.CNT<1>:" Labels/Docs (Y/N) : ",'YN',1
             IF NOT(ANS) THEN RETURN
          END CASE

          UD.LABEL.DOC.PRINT PASSER,SELCT,TOL.CNT,BOX.QTY
          MSG=''

         IF FORMAT[1,1]='B' OR FORMAT[1,1]='C' OR FORMAT[1,1]='D' THEN
             MSG = 'File Downloaded...'
          END ELSE


          IF FORM='None' OR FORM='NO' THEN
             MSG = 'Processing Complete...'
          END ELSE
             MSG = ' ':TOL.CNT<1>:' Labels/Docs Printed.'
             IF NOT(AUTORTN) THEN MSG := ' Press <Enter> to continue : '
          END
          END
          IF AUTORTN THEN
             MESS 10,10,MSG
          END ELSE
IN$$4:       INP.PROMPT ,BELL:MSG,,0
          END

          RETURN TO FINISH
*-------------------------------------------------------------------------*
SET.VARS: *** passer needs to be valid when calling this

          GEN           = PASSER<2>
          ORIG.GEN      = PASSER<3>

          IF PASSER<6> THEN
             LDID = PASSER<6>
          END

          ORIG.LDID     = PASSER<7>
          UID           = PASSER<8>
          LBL.QTY       = PASSER<9>
          UQTY          = PASSER<10>
          UQTY          = PASSER<11>
          UFORMAT       = PASSER<12>
          FORMAT        = PASSER<13>
          LDIDS         = PASSER<14>
          CTN.OID       = PASSER<15>
          TYPE          = PASSER<16>
          RCV.MODE      = PASSER<17>
          QTY           = PASSER<20>
          PRT.SELCTS    = PASSER<22>
          FMT.ID        = PASSER<23>
          PICK.CONF     = PASSER<24>
          TOTAL.PKG.CNT = PASSER<25>
          QSIGN         = PASSER<26>
          MODE          = PASSER<27>
          LD.CT         = DCOUNT(LDIDS,VM)
          TOT.PRT       = 0
          FORMATS       = RAISE(PASSER<28>)

          RETURN
*-------------------------------------------------------------------------*
FINISH:   *** exit this routine

          IF TYPE = 'T' THEN
             GEN = ORIG.GEN
          END
          WINDOW.CLOSE

          RETURN
!TSMITH~08/08/17~12:00
